package com.jiantong.news.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.news.impl.dao.QuotesDao;
import com.jiantong.news.model.Quotes;
import com.jiantong.news.service.QuotesWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 行情报价
 * Created by mz03 on 2017/3/16.
 * zyp
 */
@Slf4j
@Service
@RpcProvider
public class QuotesWriteServiceImpl implements QuotesWriteService{

    private final QuotesDao quotesDao;

    public QuotesWriteServiceImpl(QuotesDao quotesDao){
        this.quotesDao = quotesDao;
    }

    /**
     * 创建
     * @param quotes 单据对象
     * @return 主键 id
     */
    @Override
    public Response<Long> create(Quotes quotes) {
        try {
            quotesDao.create(quotes);
            return Response.ok(quotes.getId());
        }catch (Exception e) {
            log.error("failed.to.create.quotes:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("create.failed");
        }
    }

    @Override
    public Response<Integer> createQuotes(List<Quotes> quotesList) {
        try {
            return Response.ok(quotesDao.createQuotes(quotesList));
        }catch (Exception e) {
            log.error("failed.to.creates.quotes:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("creates.failed");
        }
    }

    /**
     * 添加新方法..
     */
}
